{% extends "!page.html" %}
{#
  You can't override layout.html in RTD
  https://github.com/rtfd/readthedocs.org/issues/152
  Therefore, placing in page.html
#}

{% block extrahead %}
  {# track only after cookie consent is obtained #}
  <script>
    /*
      Global variable shared with cookie consent dialog code.
      This is to use its value uniformly throughout the page.
    */
    window.g_cookieConsentId = 'CitusCookieConsentCorner';

    if (document.cookie.indexOf(window.g_cookieConsentId) == -1) {
      window.YETT_BLACKLIST = [
        /munchkin\.marketo\.net/,
        /sjs\.bizographics\.com/,
        /doubleclick\.net/,
        /cdn\.heapanalytics\.com/,
      ];
    } else {
      console.log("Cookies already accepted");
      window.YETT_BLACKLIST = [ ];
    }
  </script>
  <script src='https://unpkg.com/yett'></script>

  {{ super() }}

  {# Helper for tracking outbound links with GA #}
  <script>
    // Read The Docs is responsible for loading GA by
    // injecting a script into all pages. The function
    // below assumes that this has happened.
    window.trackOutboundLink = function(url) {
      if (typeof(ga) == 'function') {
        ga('send', 'event', 'outbound', 'click', url, {
          'transport': 'beacon',
          'hitCallback': function(){document.location = url;}
        });
        // cancel navigation due to click, allow the hitCallback to
        // navigate to the next page after ga() has registered event
        return false;
      } else {
        console.log("trackOutboundLink: Unable to access ga()");
        // ga() was a no-go so allow navigation to proceed
        return true;
      }
    };
  </script>

  {# Verify the site for Google Webmaster Tools #}
  <meta name="google-site-verification" content="v8MtCUC2nV2dO-4CSGb5flD1MyPKJvw7wBDOYRwBadw" />

  {# fonts for cookie consent box #}
  <link href="https://fonts.googleapis.com/css?family=Lato:300,300i,400,400i,700,700i" rel="stylesheet" />

  {# Last in <head> to override any canonical link that sphinx adds #}
  {% if pagename in canonical_urls %}
    <link rel="canonical" href="{{ canonical_urls[pagename] }}" />
  {% endif %}
{% endblock %}

{% block sidebartitle %}
  <a class="skiplink" href="#maincontent">Skip to main content ></a>
  <a href="https://citusdata.com" class="homepage">
    <img src={{ pathto('_images/logo.png', 1) }} class="logo" alt="Citus Data logo" />
  </a>

  {{ super() }}
{% endblock %}

{% block body %}
  <div id="maincontent" />

  {{ super() }}

  <div class="new" id="consentBox">
    <div class="consent-text">
      <p>This site uses cookies for analytics, personalized content and ads. By continuing to browse this site, you agree to this use. <a href="https://www.citusdata.com/privacy#cookies" id="cookiesLink">Learn&nbsp;more</a>.</p>
    </div>
    <div class="consent-button">
      <button class="btn" id="closeConsent">CLOSE</button>
    </div>
  </div>

{% endblock %}

{% block footer %}
  {{ super() }}

  {# Heap Analytics #}
  <script type="text/javascript">
    window.heap=window.heap||[],heap.load=function(e,t){window.heap.appid=e,window.heap.config=t=t||{};var r=t.forceSSL||"https:"===document.location.protocol,a=document.createElement("script");a.type="text/javascript",a.async=!0,a.src=(r?"https:":"http:")+"//cdn.heapanalytics.com/js/heap-"+e+".js";var n=document.getElementsByTagName("script")[0];n.parentNode.insertBefore(a,n);for(var o=function(e){return function(){heap.push([e].concat(Array.prototype.slice.call(arguments,0)))}},p=["addEventProperties","addUserProperties","clearEventProperties","identify","removeEventProperty","setEventProperties","track","unsetEventProperty"],c=0;c<p.length;c++)heap[p[c]]=o(p[c])};
    heap.load("4002524638");
  </script>

  {# cookie consent dialog #}

  <script src='https://cdnjs.cloudflare.com/ajax/libs/jquery-cookie/1.4.1/jquery.cookie.min.js'></script>

  <script type="text/javascript">
    $(document).ready(function() {
      /* Uses global window.g_cookieConsentId defined in the <head> */

      var consentValue = 'Consented';

      var clickConsent = function () {
        if ($("#consentBox").is(":visible")) {
          if (typeof(window.yett) == 'object' &&
              typeof(window.yett.unblock) == 'function') {
            window.yett.unblock();
          } else {
            console.log("clickConsent: Unable to access window.yett.unblock()");
          }
          // "slideUp" means "hide," it is not a direction of movement
          $("#consentBox").slideUp("linear");
          $.cookie(window.g_cookieConsentId, consentValue, {
            expires: 365,
            path: '/'
          });
          if (typeof(ga) == 'function') {
            ga('set', 'allowAdFeatures', true);
            ga('send', 'event', 'cookie consent', 'accept', window.location.href);
          } else {
            console.log("clickConsent: Unable to access ga()");
          }
        }
      };

      // continuing to interact with the page consents to cookies
      $("a:not(#cookiesLink), button, iframe, input, [data-toggle*='wy-nav-top'], [data-toggle*='rst-current-version']").on(
        "click", clickConsent
      );

      if ($.cookie(window.g_cookieConsentId) != consentValue) {
        // "slideDown" means "show," it's not a direction of movement
        $("#consentBox").slideDown("linear");
      }
    });
  </script>
{% endblock %}
